<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    package org.hackystat.sensorbase.resource.projects;<a name="line.1"></a>
<FONT color="green">002</FONT>    <a name="line.2"></a>
<FONT color="green">003</FONT>    import javax.xml.datatype.XMLGregorianCalendar;<a name="line.3"></a>
<FONT color="green">004</FONT>    <a name="line.4"></a>
<FONT color="green">005</FONT>    import org.hackystat.sensorbase.resource.projects.jaxb.Project;<a name="line.5"></a>
<FONT color="green">006</FONT>    import org.hackystat.utilities.tstamp.Tstamp;<a name="line.6"></a>
<FONT color="green">007</FONT>    <a name="line.7"></a>
<FONT color="green">008</FONT>    /**<a name="line.8"></a>
<FONT color="green">009</FONT>     * Methods that really should be part of the Project JAXB class, but I don't know<a name="line.9"></a>
<FONT color="green">010</FONT>     * how to extend that class with additional methods.<a name="line.10"></a>
<FONT color="green">011</FONT>     *  <a name="line.11"></a>
<FONT color="green">012</FONT>     * @author Philip Johnson<a name="line.12"></a>
<FONT color="green">013</FONT>     */<a name="line.13"></a>
<FONT color="green">014</FONT>    public class ProjectUtils {<a name="line.14"></a>
<FONT color="green">015</FONT>      <a name="line.15"></a>
<FONT color="green">016</FONT>      /**<a name="line.16"></a>
<FONT color="green">017</FONT>       * Returns true if the passed date falls within the project start date. Due to time zones<a name="line.17"></a>
<FONT color="green">018</FONT>       * and other issues, we are going to be lenient with the definition.  Basically, we will <a name="line.18"></a>
<FONT color="green">019</FONT>       * accept the day before the project start date, and any day afterwards. <a name="line.19"></a>
<FONT color="green">020</FONT>       * @param project The project.<a name="line.20"></a>
<FONT color="green">021</FONT>       * @param date The date of interest. <a name="line.21"></a>
<FONT color="green">022</FONT>       * @return True if date is after the day before the project start date.<a name="line.22"></a>
<FONT color="green">023</FONT>       */<a name="line.23"></a>
<FONT color="green">024</FONT>      public static boolean isValidStartTime(Project project, XMLGregorianCalendar date) {<a name="line.24"></a>
<FONT color="green">025</FONT>        XMLGregorianCalendar lenientStart = Tstamp.incrementDays(project.getStartTime(), -2);<a name="line.25"></a>
<FONT color="green">026</FONT>        return Tstamp.lessThan(lenientStart, date);<a name="line.26"></a>
<FONT color="green">027</FONT>      }<a name="line.27"></a>
<FONT color="green">028</FONT>      <a name="line.28"></a>
<FONT color="green">029</FONT>      /**<a name="line.29"></a>
<FONT color="green">030</FONT>       * Returns true if the passed date falls within the project end date.  Due to time zones<a name="line.30"></a>
<FONT color="green">031</FONT>       * and other issues, we will accept the day after the official project end date as well.<a name="line.31"></a>
<FONT color="green">032</FONT>       * @param project The project.<a name="line.32"></a>
<FONT color="green">033</FONT>       * @param date The date of interest. <a name="line.33"></a>
<FONT color="green">034</FONT>       * @return True if date is less than to equal to the project start date. <a name="line.34"></a>
<FONT color="green">035</FONT>       */<a name="line.35"></a>
<FONT color="green">036</FONT>      public static boolean isValidEndTime(Project project, XMLGregorianCalendar date) {<a name="line.36"></a>
<FONT color="green">037</FONT>        XMLGregorianCalendar lenientEnd = Tstamp.incrementDays(project.getEndTime(), 2);<a name="line.37"></a>
<FONT color="green">038</FONT>        return Tstamp.lessThan(date, lenientEnd); <a name="line.38"></a>
<FONT color="green">039</FONT>      }<a name="line.39"></a>
<FONT color="green">040</FONT>    <a name="line.40"></a>
<FONT color="green">041</FONT>      /**<a name="line.41"></a>
<FONT color="green">042</FONT>       * Returns true if the start and end date constitute a valid project interval. This means<a name="line.42"></a>
<FONT color="green">043</FONT>       * that isValidStartDate() and isValidEndDate() return true, and that start is less than end.<a name="line.43"></a>
<FONT color="green">044</FONT>       * @param project The project. <a name="line.44"></a>
<FONT color="green">045</FONT>       * @param start The proposed start date.<a name="line.45"></a>
<FONT color="green">046</FONT>       * @param end The proposed end date. <a name="line.46"></a>
<FONT color="green">047</FONT>       * @return True if start and end are acceptable according to the project definition.<a name="line.47"></a>
<FONT color="green">048</FONT>       */<a name="line.48"></a>
<FONT color="green">049</FONT>      public static boolean isValidInterval(Project project, XMLGregorianCalendar start, <a name="line.49"></a>
<FONT color="green">050</FONT>          XMLGregorianCalendar end) {<a name="line.50"></a>
<FONT color="green">051</FONT>        return (isValidStartTime(project, start) &amp;&amp; isValidEndTime(project, end) &amp;&amp;<a name="line.51"></a>
<FONT color="green">052</FONT>        Tstamp.lessThan(start, end));<a name="line.52"></a>
<FONT color="green">053</FONT>      }<a name="line.53"></a>
<FONT color="green">054</FONT>    }<a name="line.54"></a>




























































</PRE>
</BODY>
</HTML>
